<?php require_once('../Connections/conn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_conn, $conn);
$query_rs_lnk = "SELECT categoryid, categoryname FROM category WHERE parentid = 0";
$rs_lnk = mysql_query($query_rs_lnk, $conn) or die(mysql_error());
$row_rs_lnk = mysql_fetch_assoc($rs_lnk);
$totalRows_rs_lnk = mysql_num_rows($rs_lnk);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

  <?php 
  if($totalRows_rs_lnk>0){
	  ?>
      <ol>
	  <?php 
  	do { ?>

     <?php 
	 $parentid =  $row_rs_lnk['categoryid'];
	 //echo $row_rs_lnk['categoryid']; 
	 echo "<li>". $row_rs_lnk['categoryname']."</li>"; 
	 	
			$query_rs_lk = "SELECT categoryid, categoryname FROM category WHERE parentid = $parentid";
			$rs_lk = mysql_query($query_rs_lk, $conn) or die(mysql_error());
			$row_rs_lk = mysql_fetch_assoc($rs_lk);
			$totalRows_rs_lk = mysql_num_rows($rs_lk);
	  		if($totalRows_rs_lk>0){
				echo "<ol>";
				do{
					echo "<li>".$row_rs_lk["categoryname"]."</li>";
					$parentid = $row_rs_lk["categoryid"];
					$query_rs_lks = "SELECT categoryid, categoryname FROM category WHERE parentid = $parentid";
					$rs_lks = mysql_query($query_rs_lks, $conn) or die(mysql_error());
					$row_rs_lks = mysql_fetch_assoc($rs_lks);
					$totalRows_rs_lks = mysql_num_rows($rs_lks);
					if($totalRows_rs_lks>0){
				echo "<ol>";
				do{
					echo "<li>".$row_rs_lks["categoryname"]."</li>";
					$parentid = $row_rs_lks["categoryid"];
				  }while($row_rs_lks = mysql_fetch_assoc($rs_lks));
						echo "</ol>";
					}
					
				  }while($row_rs_lk = mysql_fetch_assoc($rs_lk));
			echo "</ol>";
		}?>

    <?php } while ($row_rs_lnk = mysql_fetch_assoc($rs_lnk)); 
?> 
</ol>
<?php }?>
</table>
</body>
</html>
<?php
function processLinks($parentid){


}
mysql_free_result($rs_lnk);
?>
